<?php

(defined('BASEPATH')) or exit('No direct script access allowed');

/* load the HMVC_Loader class */
require APPPATH . 'third_party/HMVC/Loader.php';

class CMS_Loader extends HMVC_Loader {

    //put your code here
    public function __construct() {
        parent::__construct();
        parent::initialize();
        parent::config('cms');
        $this->_ci_view_paths = array(
            APPPATH . 'views/' => TRUE,
            rtrim(FCPATH . base_pasta_templates() . '/' . base_template_cms() , '/') . '/' => TRUE, //'templates/' . config_item('template_cms') . '/' => TRUE,
            rtrim(FCPATH . base_pasta_templates() . '/' . base_template_site() , '/') . '/' => TRUE, //'templates/' . config_item('template_site')
                //FCPATH . 'modulos/' . config_item('template') . '/views/' => TRUE
        );
    }

    /**
     * Database Loader
     *
     * @param	string	the DB credentials
     * @param	bool	whether to return the DB object
     * @param	bool	whether to enable active record (this allows us to override the config setting)
     * @return	object
     */
    public function database($params = '', $return = FALSE, $active_record = NULL) {
        // Grab the super object
        $CI = & get_instance();

        // Do we even need to load the database class?
        if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db)) {
            return FALSE;
        }
        require_once(FCPATH . APPPATH . 'database/DB.php');
        if ($return === TRUE) {
            return DB($params, $active_record);
        }

        // Initialize the db variable.  Needed to prevent
        // reference errors with some configurations
        $CI->db = '';

        // Load the DB class
        $CI->db = & DB($params, $active_record);
    }

}